<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/4/27
 * Time: 10:16
 */

namespace app\adminapiv3\service;


class IpsWebsiteProtect extends Base
{
    /**
     * @name 站点列表
     * @param $hostId
     * @param $params
     * @param $limit
     * @return mixed
     * @author wx
     * @date 2020/4/27 10:19
     */
    function list($hostId, $params, $limit)
    {
        $server = new \app\common\service\IpsWebsiteProtect();
        $data = $server->list($hostId, $params, $limit);

        return $data;
    }

    /**
     * @name 列表首页数据
     * @author wx
     * @date 2020/4/27 10:23
     */
    function data()
    {
        $server = new \app\common\service\IpsWebsiteProtect();
        $data['domain_name'] = $server->data();

        return $data;
    }

    /**
     * @name 添加
     * @param $insertData
     * @author wx
     * @date 2020/4/27 10:34
     */
    function add($insertData)
    {
        $this->checkOptionHost($insertData['host_id']);

        if(empty($insertData)){
            $this->setError($this->CODE_FAIL,'参数错误');
        }

        $insertData['ctime'] = time();

        $server = new \app\common\service\IpsWebsiteProtect();
        $server->add($insertData);

        return true;
    }

    /**
     * @name 删除
     * @param $id
     * @author wx
     * @date 2020/4/27 10:43
     */
    function del($id)
    {
        if(empty($id)){
            $this->setError($this->CODE_FAIL,'参数错误');
        }

        $server = new \app\common\service\IpsWebsiteProtect();
        $condition[] = ['id', 'in', $id];
        $server->del($condition);
    }

    /**
     * @name 重新导入站点
     * @param $hostId
     * @return bool
     * @author wx
     * @date 2020/4/27 10:47
     */
    function delHostId($hostId)
    {
        if(empty($hostId)){
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $condition['host_id'] = $hostId;

        $server = new \app\common\service\IpsWebsiteProtect();
        $server->del($condition);

        return true;
    }

    /**
     * @name 详情
     * @param $hostId
     * @param $id
     * @return array|bool|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date 2020/4/27 10:54
     */
    function info($hostId, $id)
    {
        if(empty($hostId) || empty($id)){
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $server = new \app\common\service\IpsWebsiteProtect();
        $condition['id'] = $id;
        $condition['host_id'] = $hostId;
        $info = $server->findData($condition);

        return $info;
    }

    /**
     * @name 编辑
     * @param $id
     * @param $update
     * @return bool
     * @author wx
     * @date 2020/4/27 10:55
     */
    function modify($id, $update)
    {
        if(empty($id) || empty($update)){
            $this->setError($this->CODE_FAIL,'参数错误');
            return false;
        }

        $server = new \app\common\service\IpsWebsiteProtect();
        $condition['id'] = $id;
        $server->modify($condition, $update);

        return true;
    }



}